home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / cfuncs.zip / FRAME.C < prev    next >
Text File  |  1991-08-07  |  5KB  |  178 lines

  1. #include <funcs.h>
  2. char    nullc[] = "\0";
  3. int FG = -1, BG = -1;
  4.  
  5. /*-----------------------Frame-----------------------------------*/
  6. /*DESCRIPTION:  Displays a frame of specified colors, dimensions */
  7. /*    and text on the console                     */
  8. /*                                 */
  9. /*INPUT: type FrameDataType defined in funcs.h             */
  10. /*   .X  x coordinate of upper left corner of frame         */
  11. /*   .Y  y coordinate of upper left corner of frame         */
  12. /*   .L  length of frame                     */
  13. /*   .W  width of frame                         */
  14. /*   .F  foreground color                     */
  15. /*   .B  background color                     */
  16. /*   .BorderType   0 = ══ border                      */
  17. /*              1 = ── border                      */
  18. /*              2 = ═ top, │ sides                      */
  19. /*              3 = ─ top, ║ sides                      */
  20. /*              4 = plain border                      */
  21. /*   .txt[X] pointer to char.  X range 0-24             */
  22. /*   .clear - 0 clear .txt after displaying             */
  23. /*            1 leave .txt unchanged                 */
  24. /*          2 initialize .txt array (no display)         */
  25. /*          0 or 1 + 10 -- don't disp a shadow around the frame*/
  26. /*USES: strspc, writeat                         */
  27. /*---------------------------------------------------------------*/
  28.  
  29. void Frame ( FrameDataType *Framedat )
  30.  
  31. {
  32.     int i, len;
  33.  
  34.     char line[160];
  35.     char BorderCh[5][7] = {"╔═╗╚╝║", "┌─┐└┘│", "╒═╕╘╛│", "╓─╖╙╜║", "      "};
  36.  
  37.  
  38.     if(Framedat->clear == 2)
  39.     {    for (i = 0; i < 24; ++i)
  40.         Framedat->txt[i] = nullc;
  41.     Framedat->clear = 0;
  42.     return;
  43.     }
  44.     if(Framedat->BorderType >4 || Framedat->BorderType < 0)
  45.        Framedat->BorderType = 0;
  46.  
  47. /**********************************
  48.      check and evaluate input data
  49. ***********************************/
  50.  
  51.     if (Framedat->X <= 0  || Framedat->X >= 80 )
  52.  
  53.      {
  54.       printf("\nBad X Range For Frame");
  55.       exit(1);
  56.      }
  57.  
  58.     if (Framedat->Y <= 0  || Framedat->Y >= 25 )
  59.      {
  60.       printf("\nBad Y Range For Frame");
  61.       exit(1);
  62.      }
  63.  
  64.     if (Framedat->W <= 1  || Framedat->X+Framedat->W > 80 )
  65.      {
  66.       printf("\nBad Width Range For Frame");
  67.       exit(1);
  68.      }
  69.  
  70.     if (Framedat->L <= 1  || Framedat->Y+Framedat->L + (Framedat->clear >= 10) ? 0:1 > 25 )
  71.      {
  72.       printf("\nBad Length Range For Frame");
  73.       exit(1);
  74.      }
  75.  
  76. /******************
  77.     Print Top Line
  78. *******************/
  79.  
  80.     line[0] = BorderCh[Framedat->BorderType][0];
  81.     strnchr(line+1, BorderCh[Framedat->BorderType][1], Framedat->W-2);
  82.     *(line+Framedat->W-1) = BorderCh[Framedat->BorderType][2];
  83.     *(line+Framedat->W) = '\0';
  84.     WriteAt(Framedat->X, Framedat->Y, Framedat->F, Framedat->B, line);
  85.  
  86. /*    gotoxy ( Framedat->X, Framedat->Y );
  87.  
  88.     putch(BorderCh[Framedat->BorderType][0]);
  89.  
  90.     for ( i=Framedat->X+1; i<=Framedat->X+Framedat->W-1; i++)
  91.       putch(BorderCh[Framedat->BorderType][1] );
  92.  
  93.     putch  (BorderCh[Framedat->BorderType][2]);
  94. */
  95. /***************
  96.     Print Middle
  97. ****************/
  98.     for ( i = 0; i < Framedat->L-2; i++)
  99.      {
  100.       strcpy(line, BorderCh[Framedat->BorderType]+5);
  101.       if(!Framedat->txt[i]) Framedat->txt[i] = nullc;
  102.       strcat(line, Framedat->txt[i]);
  103.       len = strlen(line);
  104.       strspc(line + len, Framedat->W - len);
  105.       strcpy(line + Framedat->W-1, BorderCh[Framedat->BorderType]+5);
  106.  
  107.       Write(line);
  108.  
  109.       if (Framedat->clear % 10 != 1)
  110.     Framedat->txt[i] = nullc;
  111.  
  112.      }
  113.  
  114. /*********************
  115.     Print Bottom Line
  116. ***********************/
  117.     line[0] = BorderCh[Framedat->BorderType][3];
  118.     strnchr(line+1, BorderCh[Framedat->BorderType][1], Framedat->W-2);
  119.     *(line+Framedat->W-1) = BorderCh[Framedat->BorderType][4];
  120.     *(line+Framedat->W) = '\0';
  121.     Write(line);
  122.  
  123.     if(Framedat->clear >=10) return;
  124.  
  125. /***********************
  126.     Print bottom shadow
  127. ************************/
  128.  
  129.    SaveScrn(Framedat->X, Framedat->Y+Framedat->L, Framedat->W-1, 1, line);
  130.  
  131. /* make every other char (the attribute bytes) = DARKGRAY fg, BLACK bg */
  132.    for(i=1; i < (Framedat->W-1)*2; i +=2)
  133.      line[i] = 8;
  134.    RestScrn(Framedat->X, Framedat->Y+Framedat->L, Framedat->W-1, 1, line);
  135.  
  136.  
  137. /*    gettext(Framedat->X-1, Framedat->Y+Framedat->L+1, Framedat->X+Framedat->W,
  138.                           Framedat->Y+Framedat->L+1, line );
  139.  
  140.     gotoxy(Framedat->X-1,Framedat->Y+Framedat->L+1);
  141.  
  142.     j = (Framedat->W) * 2;
  143.  
  144.     for ( i=0; i<=j; i+=2)
  145.       putch(line[i]); */
  146.  
  147. /***********************
  148.    print side shadow
  149. ************************/
  150.  
  151.    SaveScrn(Framedat->X-1, Framedat->Y+1, 1, Framedat->L, line);
  152.  
  153. /* make every other char (the attribute bytes) = DARKGRAY fg, BLACK bg */
  154.    for(i=1; i < (Framedat->L)*2; i +=2)
  155.      line[i] = 8;
  156.    RestScrn(Framedat->X-1, Framedat->Y+1, 1, Framedat->L, line);
  157.  
  158. }
  159. /*main()
  160. {
  161.     int i, j;
  162.     FrameDataType  Fr;
  163.  
  164.     textcolor(4);
  165.     textbackground(2);
  166.     for(i=0; i<80; ++i)
  167.       for(j=65; j<90; ++j)
  168.     putch(j);
  169.     Fr.X  = 20; Fr.Y = 8;
  170.     Fr.L = 8; Fr.W = 40;
  171.     Fr.F = 7; Fr.B = 1;
  172.     Fr.clear = 2;
  173.     Frame(&Fr);
  174.     Fr.txt[1] = "  hello world";
  175.     Fr.txt[2] = "from this little frame.";
  176.     Frame(&Fr);
  177. } */
  178.